            package com.jiruan.invoicemanagementsystem.controller;


            import com.google.gson.Gson;
            import com.google.gson.JsonObject;
            import com.jiruan.invoicemanagementsystem.pojo.InvoicingRecord;
            import com.jiruan.invoicemanagementsystem.service.IBaseDateService;
            import com.jiruan.invoicemanagementsystem.service.IInvoicingRecord;
            import com.jiruan.invoicemanagementsystem.service.imp.IBaseDateServiceImp;
            import com.jiruan.invoicemanagementsystem.service.imp.IInvoicingRecordImp;
            import com.jiruan.invoicemanagementsystem.util.PageHelper;
            import com.jiruan.invoicemanagementsystem.vo.InvoicingRecordDetail;
            import com.jiruan.invoicemanagementsystem.vo.InvoicingRecordShow;
            import com.jiruan.invoicemanagementsystem.vo.StatisticalInfoShow;

            import javax.servlet.ServletException;
            import javax.servlet.annotation.WebServlet;
            import javax.servlet.http.HttpServletRequest;
            import javax.servlet.http.HttpServletResponse;
            import javax.servlet.http.HttpSession;
            import java.io.IOException;
            import java.text.ParseException;
            import java.text.SimpleDateFormat;
            import java.util.ArrayList;
            import java.util.Date;


            //登录后欢迎页
            @WebServlet("/fenye/*")
            public class WelcomePageController extends BaseController {

               private IInvoicingRecord iir=new IInvoicingRecordImp();
               private IBaseDateService ibds=new IBaseDateServiceImp();

                public void getListPage(HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException {
                    PageHelper ph=new PageHelper();
                    int indexpage=Integer.parseInt(request.getParameter("indexpage"));

                    // 2. 处理日期（前端未传/空值时设为 null，避免 parse 异常）

                    Date createTime=null;


                    String createTimeStr = request.getParameter("createTime");
        //            System.out.println(createTimeStr+"日期1");

                    if (createTimeStr != null && !"".equals(createTimeStr.trim())) {
                        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
                        createTime = sdf.parse(createTimeStr);
                    }


                    String status=request.getParameter("status");
                    String title=request.getParameter("title");

                    String mins=request.getParameter("min");
                    String maxs=request.getParameter("max");

                    Double min=null;
                    Double max=null;

                    if (mins !=null && !mins.trim().isEmpty() ){min=Double.parseDouble(mins);}

                    if (maxs !=null && !maxs.trim().isEmpty()) {  max=Double.parseDouble(maxs);}


                    //  发票申请日期"、"处理状态"，"发票种类"   min: 发票金额条件的最小值     *  max: 发票金额条件的最大值
                    InvoicingRecordShow invoicingRecord=new InvoicingRecordShow();
                    invoicingRecord.setCreateTime(createTime);
                    invoicingRecord.setTitle(title);
                    invoicingRecord.setStatus(status);

        //            System.out.println(invoicingRecord.getCreateTime()+"日期");


                    ph.setPageIndex(indexpage);  //   按 4 得到第四页
                    ph.setDateCount(iir.getCountOfInvoicingRecord(invoicingRecord,min,max));   //  获得总条数 总条数根据当前要显示几页需求得到 总页数
                    ph.setListIndex(iir.getMessageOfInvoicingRecord(ph,invoicingRecord,min,max));  //获得数据集合


        //        ArrayList<Object> o=ph.getListIndex();
        //        for (Object order:o){
        //            InvoicingRecordShow i=(  InvoicingRecordShow) order;
        //            System.out.println(i.getTitle());
        //        }

                    response.getWriter().println(new Gson().toJson(ph));
                }



                public void queryInvoiceTotal(HttpServletRequest request, HttpServletResponse response) throws IOException {
                    StatisticalInfoShow sis=new StatisticalInfoShow();

                    Double tHI=iir.getTAofHistoricalInvoice();
                    Double use=sis.getTotalInvoiceAmount()-tHI;

                    sis.setTaoHistoricalInvoice(String.valueOf(tHI));  //存入历史总金额
                    sis.setCanInvoiceAmount(String.valueOf(use));  //存入可开票金额




                    response.getWriter().println(new Gson().toJson(sis));


                }

                //获得邮箱展示部分
                public void getDefaultShowEmail(HttpServletRequest request, HttpServletResponse response) throws IOException {
                    InvoicingRecordDetail i=ibds.queryDefaultShowEmail();
                    response.getWriter().println(new Gson().toJson(i));
                }


                //获得详情页
                public void getDetail(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
                    String upLinkAddress=request.getParameter("upLinkAddress");
                   InvoicingRecordDetail Details=iir.getInvoicingAccordingTo(upLinkAddress);

                    response.getWriter().println(new Gson().toJson(Details));

                }

                //退票操作
                public void backInvoice(HttpServletRequest request, HttpServletResponse response) throws IOException {
                    String upLinkAddress=request.getParameter("upLinkAddress");

                   boolean judge=iir.refundTickById(upLinkAddress);
                    response.getWriter().println(new Gson().toJson(judge));
                }

            }
